import { Decorator_DtoIsNumber_Base } from '@/common/decorators/dtoIsNumber';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsArray, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import {
  Constant_Enum_Enum_Coupon_CouponStatus,
  Constant_Enum_Enum_Coupon_PlatformType,
  Constant_Enum_Enum_Coupon_Scope,
  Constant_Enum_Enum_Coupon_TimeLimitType,
  Constant_Enum_Enum_Coupon_Type,
  Constant_Enum_Enum_Coupon_UseStatus,
  Constant_Enum_Name_Coupon_CouponStatus,
  Constant_Enum_Name_Coupon_PlatformType,
  Constant_Enum_Name_Coupon_Scope,
  Constant_Enum_Name_Coupon_TimeLimitType,
  Constant_Enum_Name_Coupon_Type,
  Constant_Enum_Name_Coupon_UseStatus,
  IConstant_Enum_Type_Coupon_CouponStatus,
  IConstant_Enum_Type_Coupon_PlatformType,
  IConstant_Enum_Type_Coupon_Scope,
  IConstant_Enum_Type_Coupon_TimeLimitType,
  IConstant_Enum_Type_Coupon_Type,
  IConstant_Enum_Type_Coupon_UseStatus,
} from '@/common/constants/enum';
import { Type } from 'class-transformer';

export class Coupon_Create_Dto {
  @IsArray()
  @IsOptional()
  @Type(() => Number)
  @IsInt({ each: true, message: '数组每一项必须是数字类型' })
  @ApiProperty({ description: '优惠券分类ID', type: [Number] })
  couponSortIds: number[];

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ description: '优惠券名称' })
  couponName: string;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '优惠券备注' })
  couponRemark?: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    description: '优惠券类型' + Constant_Enum_Name_Coupon_Type,
    enum: Constant_Enum_Enum_Coupon_Type,
  })
  couponType: IConstant_Enum_Type_Coupon_Type;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '满减金额(元)' })
  reduceMoney?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '满多少金额' })
  reducePrice?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ type: 'float', example: 9.5, description: '折扣（例如:输入9为9折,输入9.5为9.5折）' })
  discount?: number;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    description: '针对人群 ' + Constant_Enum_Name_Coupon_Scope,
    enum: Constant_Enum_Enum_Coupon_Scope,
  })
  couponScope: IConstant_Enum_Type_Coupon_Scope;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    description: '使用时间限制类型' + Constant_Enum_Name_Coupon_TimeLimitType,
    enum: Constant_Enum_Enum_Coupon_TimeLimitType,
  })
  timeLimitType: IConstant_Enum_Type_Coupon_TimeLimitType;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '固定时间开始范围', type: 'bigint' })
  fixedTimeStart?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '固定时间结束范围', type: 'bigint' })
  fixedTimeEnd?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '领取后有效天数' })
  validDays?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '兑换码' })
  exchangeCode?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    description: '商品类型' + Constant_Enum_Name_Coupon_PlatformType,
    enum: Constant_Enum_Enum_Coupon_PlatformType,
  })
  couponPlatformType?: IConstant_Enum_Type_Coupon_PlatformType;

  // @IsArray()
  // @IsOptional()
  // @ApiProperty({ description: '商品规格' })
  // couponProducts?: Coupon_CreateUtil_Dto[];

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    description: '状态' + Constant_Enum_Name_Coupon_CouponStatus,
    enum: Constant_Enum_Enum_Coupon_CouponStatus,
  })
  couponStatus: IConstant_Enum_Type_Coupon_CouponStatus;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    description: '停用状态' + Constant_Enum_Name_Coupon_UseStatus,
    enum: Constant_Enum_Enum_Coupon_UseStatus,
  })
  useStatus: IConstant_Enum_Type_Coupon_UseStatus;
}

export class Coupon_Web_Find_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  size?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  page?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '虚拟商品Id' })
  couponProductId?: number;
}
export class Coupon_Find_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  size?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  page?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '优惠券分类' })
  couponSortIds?: number[];

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '优惠券名称' })
  couponName?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    description: '优惠券类型' + Constant_Enum_Name_Coupon_Type,
    enum: Constant_Enum_Enum_Coupon_Type,
  })
  couponType?: IConstant_Enum_Type_Coupon_Type;

  @IsString()
  @IsOptional()
  @ApiProperty({
    description: '针对人群' + Constant_Enum_Name_Coupon_Scope,
    enum: Constant_Enum_Enum_Coupon_Scope,
  })
  couponScope?: IConstant_Enum_Type_Coupon_Scope;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '兑换码' })
  exchangeCode?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    description: '商品类型' + Constant_Enum_Name_Coupon_PlatformType,
    enum: Constant_Enum_Enum_Coupon_PlatformType,
  })
  couponPlatformType?: IConstant_Enum_Type_Coupon_PlatformType;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '虚拟商品规格Id' })
  couponProductIds?: number[];

  @IsString()
  @IsOptional()
  @ApiProperty({
    description: '状态' + Constant_Enum_Name_Coupon_CouponStatus,
    enum: Constant_Enum_Enum_Coupon_CouponStatus,
  })
  couponStatus?: IConstant_Enum_Type_Coupon_CouponStatus;
}

export class Coupon_Update_Dto extends PartialType(Coupon_Create_Dto) {
  @Decorator_DtoIsNumber_Base()
  @IsNotEmpty()
  id: number;
}
